package org.example.campsys.controller;

import org.example.campsys.model.ActivityInfo;
import org.example.campsys.model.ClassInfo;
import org.example.campsys.model.Result;

import org.example.campsys.model.UserInfo;
import org.example.campsys.service.RootService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/root")
public class RootController {
    @Autowired
    public RootService rootService;

    @RequestMapping("/select")
    public Result selUser(){

        return Result.success("查询成功",rootService.selUser());
    }
    @RequestMapping("/addmanager")
    public Result addManager(Integer userId){
        rootService.addManager(userId);
        return Result.success("添加成功",true);//添加活动管理员
    }
    @RequestMapping("/adduser")//注册
    public Result register(@RequestBody UserInfo userInfo){
        if (StringUtils.hasLength(userInfo.getLoginName()) && StringUtils.hasLength(userInfo.getPassword())){
            rootService.addUser(userInfo);
            rootService.addRole(userInfo.getId(), userInfo.getRoleId());
            return Result.success("添加成功",true);
        }
        return Result.fail("输入账号或密码不能为空！",-1);
    }
    @RequestMapping("/mngactivity")
    public Result mngActivity(@RequestBody ActivityInfo activityInfo){
        return Result.success("修改成功",rootService.mngActivity(activityInfo));
    }
    @RequestMapping("/mngclass")
    public Result mngClass(@RequestBody ClassInfo classInfo){
        rootService.mngClass(classInfo);
        return Result.success("编辑成功", classInfo);
    }
    @RequestMapping("/upduser")
    public Result updUser(@RequestBody UserInfo userInfo){
        rootService.updUser(userInfo);
        return Result.success("修改成功",true);
    }


}
